package com.xc.freeapp.account.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.wordnik.swagger.annotations.Api;
import com.wordnik.swagger.annotations.ApiOperation;
import com.xc.freeapp.bean.AuthInfo;
import com.xc.freeapp.entity.Department;
import com.xc.freeapp.entity.Departments;
import com.xc.freeapp.exception.BaseException;
import com.xc.freeapp.service.HospitalService;
import com.xc.freeapp.util.AuthUtil;
import com.xc.freeapp.util.TokenAnnotation;
import com.xc.freeapp.util.UploadUtil;
@Controller
@RequestMapping("/v2/deparment")
@Api(value="/V2deparment",description = "科室信息")
public class DeparmentControllerV2 extends AbstractController {
	@Autowired
	private HospitalService hospitalService;
	/**
	 *  获取科室
	 */
	@TokenAnnotation(required=false)
	@RequestMapping(value = "", method = RequestMethod.GET)
	@ResponseBody
	@ApiOperation(value = "获取科室")
	public  List<Department> getAllDeparment() throws BaseException{
		AuthInfo authInfo = AuthUtil.getAuthInfo(getRequest());
        Map<String , Object> paramsmap = new HashMap<String, Object>();
        paramsmap.put("businessId", authInfo.getAppId());
        List<Department> departmentlist = hospitalService.getAllDeparment(authInfo.getAppIntId());
        for (Department department : departmentlist) {
        	department.setPics(UploadUtil.urlConversion(department.getPics()));
        	if(!"".equals(department.getPics())){
        		department.setPics2(department.getPics()+"?imageMogr2/thumbnail/200x200!/gravity/Center/crop/x150");
        	}
        	
		}
        
		return departmentlist;
	}
	
	/**
	 * 特色科室/科室分类(只查询主科室)
	 */
	@TokenAnnotation(required=false)
	@RequestMapping(value = "/specialDepartments", method = RequestMethod.GET)
	@ResponseBody
	@ApiOperation(value = "查询所有科室")
	public  List<Department> getSpecialDepartments(@RequestParam("querytype") String querytype) throws BaseException{
		AuthInfo authInfo = AuthUtil.getAuthInfo(getRequest());
        Map<String , Object> paramsmap = new HashMap<String, Object>();
        paramsmap.put("businessId", authInfo.getAppId());
        paramsmap.put("querytype", querytype);
        List<Department> departmentlist = hospitalService.getDeparmentList(paramsmap);
//        List<Department> departmentlist = hospitalService.getAllDeparment(authInfo.getAppIntId());
        for (Department department : departmentlist) {
        	department.setPics(UploadUtil.urlConversion(department.getPics()));
		}
		return departmentlist;
	}

	/**
	 * 特色科室/科室分类
	 */
	@TokenAnnotation(required=false)
	@RequestMapping(value = "/departmentsTree", method = RequestMethod.GET)
	@ResponseBody
	@ApiOperation(value = "科室(主科室,子科室 Tree显示)")
	public  List<Departments> getSpecialDepartmentsTree(@RequestParam(required=false,value="querytype") String querytype) throws BaseException{
		AuthInfo authInfo = AuthUtil.getAuthInfo(getRequest());
		if(querytype==null){
			querytype="2";
		}
        Map<String , Object> paramsmap = new HashMap<String, Object>();
        paramsmap.put("businessId", authInfo.getAppId());
        paramsmap.put("querytype", querytype);
        List<Departments> departmentlist = hospitalService.getDeparmentsTreeList(paramsmap);
        for (Departments department : departmentlist) {
        	department.setPics(UploadUtil.urlConversion(department.getPics()));
		}
		return departmentlist;
	}

}
